package io.renren.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.renren.entity.EvaluationInformationEntity;
import io.renren.entity.SysUserEntity;
import io.renren.utils.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.entity.EmployeePerformanceManagementEntity;
import io.renren.service.EmployeePerformanceManagementService;


/**
 * 员工绩效管理
 * 
 * @author zhangheng
 * @email zh_123shmily@163.com
 * @date 2017-07-11 17:19:09
 */
@RestController
@RequestMapping("employeeperformancemanagement")
public class EmployeePerformanceManagementController extends AbstractController{
	@Autowired
	private EmployeePerformanceManagementService employeePerformanceManagementService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("employeeperformancemanagement:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        QueryAuthority query = new QueryAuthority(params);

		List<EmployeePerformanceManagementEntity> employeePerformanceManagementList = employeePerformanceManagementService.queryList(query);
		int total = employeePerformanceManagementService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(employeePerformanceManagementList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("employeeperformancemanagement:info")
	public R info(@PathVariable("id") Integer id){
		Map map=employeePerformanceManagementService.info(id);

		//EmployeePerformanceManagementEntity employeePerformanceManagement = employeePerformanceManagementService.queryObject(id);
		
		return R.ok(map);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("employeeperformancemanagement:save")
	public R save(@RequestBody EmployeePerformanceManagementEntity employeePerformanceManagement){
		SysUserEntity entity= (SysUserEntity) ShiroUtils.getSubject().getSession().getAttribute("user");
		employeePerformanceManagement.setCdate(new Date());
		employeePerformanceManagement.setCusername(entity.getUsername());
		employeePerformanceManagement.setCompanyId(entity.getCompanyId());
		employeePerformanceManagement.setCompany(entity.getCompany());
		employeePerformanceManagement.setDept(entity.getDept());

		employeePerformanceManagement.setCreateDeptId(entity.getDeptNo());

		employeePerformanceManagementService.save(employeePerformanceManagement);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("employeeperformancemanagement:update")
	public R update(@RequestBody JSONObject params){
		employeePerformanceManagementService.update(params);
		
		return R.ok();

	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("employeeperformancemanagement:delete")
	public R delete(@RequestBody Integer[] ids){
		employeePerformanceManagementService.deleteBatch(ids);


		
		return R.ok();
	}


	@RequestMapping("/selectKPjl")
	@RequiresPermissions("employeeperformancemanagement:list")
	public R selectKPjl(@RequestParam Map<String, Object> params){

		String id = params.get("id").toString();
		List<EvaluationInformationEntity> result = employeePerformanceManagementService.selectKPjl(id);
		PageUtils pageUtil = new PageUtils(result, result.size(), 100, 1);

		return R.ok().put("page", pageUtil);
	}

	/**
	 * 保存
	 */
	@RequestMapping("/saveAndUpdateKpxx")
	@RequiresPermissions("employeeperformancemanagement:save")
	public R saveAndUpdateKpxx(@RequestBody JSONObject params){

		employeePerformanceManagementService.saveAndUpdateKpxx(params);

		return R.ok();
	}


	/**
	 * 锁定
	 */
	@RequestMapping("/lock")
	public R lock(@RequestBody Integer[] ids){
		employeePerformanceManagementService.lock(ids);



		return R.ok();
	}


}
